import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { getListAPI } from '@/request'
import type { RootObject, Children, ChinaTotal, ChinaAdd, LocalCityNCOVDataList } from './type'

export const useCounterStore = defineStore({
  id: 'counter',
  state: () => {
    return {
      list: <RootObject>{},//接口数据
      item: <Children[]>[],// 每个省的数据
      chinaAdd: <ChinaAdd>{},//较上日增加
      ChinaTotal: <ChinaTotal>{},//现有确诊,
      cictyDetail: <LocalCityNCOVDataList[]>[]
    }
  },
  actions: {
    async getList() {
      const res = await getListAPI()
      this.list = res
      this.chinaAdd = this.list.diseaseh5Shelf.chinaAdd
      this.ChinaTotal = this.list.diseaseh5Shelf.chinaTotal
      this.cictyDetail = this.list.localCityNCOVDataList.slice(0, 10)
      // console.log(res)
    }
  }
})

//   () => {
//   let list = ref<RootObject>({})

//   async function getList() {
//     const res = await getListAPI()
//     list = res
//     console.log(res)
//   }

//   return { list, getList }
// }
